home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_04 / 2n04058a < prev    next >
Text File  |  1991-01-26  |  888b  |  44 lines

  1. { RdKey to replace Turbo Pascal's ReadKey with a
  2.   function that (1) doesn't require clearing before
  3.   reuse after a call that yields ch = #0 and (2)
  4.   differentiates pairs such as BackSpace and Ctrl-h.
  5.  
  6.   Implemented in Pascal
  7. }
  8. interface
  9.  
  10. type
  11.    KeyRec = record
  12.               ch : char;
  13.               sc : byte;
  14.             end;
  15.  
  16. function RdKey(var Grabber : KeyRec)  : Char;
  17.  
  18. implementation
  19.  
  20. function RdKey{(var Grabber : KeyRec)  : Char};
  21.  
  22. var
  23.    regs : registers;
  24.  
  25. begin
  26.   regs.ah := 0;
  27.   intr($16,regs);
  28.   if regs.al <> 0 then         { ascii <> 0 }
  29.      with grabber do
  30.       begin
  31.         ch := char(regs.al);
  32.         sc := regs.ah;
  33.         RdKey := ch
  34.       end
  35.   else                         { ascii = 0 }
  36.      with grabber do
  37.       begin
  38.         ch := char(regs.ah);
  39.         sc := 0;
  40.         RdKey := Char(regs.al);
  41.       end;
  42. end;
  43.  
  44.